<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK"%>

<html>
<head> 
<script type="text/javascript" src="<%=WEBPATH%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=WEBPATH%>/dwr/util.js"></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/FormSortAction.js'></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/FormTypeBean.js'></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/FormSortBean.js'></script>
<title><html:text name="sys.name" /></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<body style="margin: 5px 0 0 1px;">
<table style="margin-left: 5px;" border="0" width="100%" cellspacing="0" cellpadding="3">
	<tr>
		<td width="130" valign="top">
		<table style="margin-left: 5px;" border="0" width="100%" cellspacing="0" cellpadding="3">
			<tr>
				<td height="500" valign="top" width="120">
				<script type="text/javascript" charset="UTF-8">
						webFXTreeConfig.rootIcon		= "<%=WEBPATH%>/images/xloadtree/page_white_magnify.gif";
						webFXTreeConfig.openRootIcon	= "<%=WEBPATH%>/images/xloadtree/page_white_magnify.gif";
						webFXTreeConfig.folderIcon		= "<%=WEBPATH%>/images/xloadtree/folder.png";
						webFXTreeConfig.openFolderIcon	= "<%=WEBPATH%>/images/xloadtree/openfolder.png";
						webFXTreeConfig.fileIcon		= "<%=WEBPATH%>/images/xloadtree/page_white_gear.gif";
						webFXTreeConfig.lMinusIcon		= "<%=WEBPATH%>/images/xloadtree/Lminus.png";
						webFXTreeConfig.lPlusIcon		= "<%=WEBPATH%>/images/xloadtree/Lplus.png";
						webFXTreeConfig.tMinusIcon		= "<%=WEBPATH%>/images/xloadtree/Tminus.png";
						webFXTreeConfig.tPlusIcon		= "<%=WEBPATH%>/images/xloadtree/Tplus.png";
						webFXTreeConfig.iIcon			= "<%=WEBPATH%>/images/xloadtree/I.png";
						webFXTreeConfig.lIcon			= "<%=WEBPATH%>/images/xloadtree/L.png";
						webFXTreeConfig.tIcon			= "<%=WEBPATH%>/images/xloadtree/T.png";
						webFXTreeConfig.blankIcon		= "<%=WEBPATH%>/images/xloadtree/blank.png";
						var treeDict = new WebFXTree("<html:text name="form.manage" />",""); 
						<html:iterator value="formSortBeans" id="formSortBeans">
							<html:if test="child==null||child==0" >
								treeDict.add(new WebFXTreeItem("<html:property value="sortName"/>","javascript:clickMenu('<html:property value="id"/>')","","<%=WEBPATH%>/images/xloadtree/folder.png"));
							</html:if>
							<html:else>
								treeDict.add(new WebFXLoadTreeItem("<html:property value="sortName"/>", "<%=WEBPATH%>/system/form/child.crm?parentId=<html:property value="id"/>","javascript:clickMenu('<html:property value="id"/>')"));
							</html:else>
						</html:iterator>
						document.write(treeDict);
						function showMenu(id){
							MenuAction.dwrView(id,fillMenu);
						}
						function fillMenu(data){
							jQuery('#id').val(data.id);
							jQuery('#name').val(data.name);
							jQuery('#parentId').val(data.parent.Id);
							jQuery('#descn').val(data.descn);
							jQuery('#image').val(data.image);
							jQuery('#forward').val(data.forward);
							jQuery('#target').val(data.target);
							jQuery('#orderBy').val(data.orderBy);
							jQuery('#menuNewTable').hide();
							jQuery('#menuDeleteButton').hide();
							jQuery('#menuDeleteButton').show();
							jQuery('#menuDetailTable').show();
						}
						function menuNew(){
							jQuery('#id').val("");
							jQuery('#name').val("");
							jQuery('#parentId').val("0");
							jQuery('#descn').val("");
							jQuery('#image').val("");
							jQuery('#forward').val("");
							jQuery('#target').val("");
							jQuery('#orderBy').val("");
							jQuery('#menuNewTable').hide();
							jQuery('#menuUpdateNewButton').hide();							
							jQuery('#menuDeleteButton').hide();
							jQuery('#menuDetailTable').show();
						}
						function menuDelete(){
							if(confirm("确定删除?")){
								var id=jQuery('#id').attr("value");
								MenuAction.dwrDelete(id,callBackFunction);
							}
						}
						function menuSave(newFlag){  
							if(newFlag){ 
								var parent={id: jQuery('#id').attr("value")};
								var MenuBean={
									id: "",
									name: jQuery('#name').attr("value"),
									descn: jQuery('#descn').attr("value"),
									image: jQuery('#image').attr("value"),
									forward: jQuery('#forward').attr("value"),
									target: jQuery('#target').attr("value"),
									target: jQuery('#orderBy').attr("value"),
									parent: parent
								};
								MenuAction.dwrSave(MenuBean,callBackFunction);
							}else{
								var parent={id: jQuery('#parentId').attr("value")};
								var MenuBean={
									id: jQuery('#id').attr("value"),
									name: jQuery('#name').attr("value"),
									descn: jQuery('#descn').attr("value"),
									image: jQuery('#image').attr("value"),
									forward: jQuery('#forward').attr("value"),
									target: jQuery('#target').attr("value"),
									target: jQuery('#orderBy').attr("value"),
									parent: parent
								};
								MenuAction.dwrSave(MenuBean,callBackFunction);
							}	
						}
						function callBackFunction(data){
							alert(data);
							window.location="<%=WEBPATH%>/system/form/index.crm";
						}
				</script>
				</td>
			</tr>
		</table>
		</td>
		<td width="10">&nbsp;</td> 
		<td width="650" valign="top" style="display:none" id="listForm">
			<input type="button" class="x-btn" id="new" name="new" value=" <html:text name="button.new"/> " onclick="javascript:newOnclick();"><br>
			<br></br><table id="listTable" width="100%" class="datatable">
				<tr class="thead"><td width="20%">编号</td><td width="80%"><html:text name="form.name" /></td></tr> 
			</table>
		</td>
		<td width="650" valign="top" style="display:none" id="detailForm">
			<table width="100%" align="center" id="mainTable">
				<tr>
					<td class="TableContent"><html:text name="form.name" /></td>
					<td class="TableData"><input type="text" id="formName" class="x-text" name="formName"
						size="30" maxlength="100"><input type="hidden" name="departId" id="departId" value="">
						<input type="hidden" name="id" id="id">
						<input type="hidden" name="userScript" id="userScript">
						<input type="hidden" name="userCss" id="userCss"> 
						<input type="hidden" name="formSortId" id="formSortId"> 
						<input type="hidden" name="isData" id="isData" value="0">
						<input type="hidden" name="sortId" id="sortId" value="0">
					</td>
				</tr> 
				<tr>
					<td colspan="2">
					<table width="100%"  class="TableBlock" align="center">
						<tr>
							<td ><!-- Editor Layer -------------------------------------->
							<FCK:editor toolbarSet="Office" basePath="${WEBPATH}" height="400" width="650"
								 instanceName="printModel"></FCK:editor></td>
						</tr>
					</table>
					</td>
				</tr>
				<tr align="center" class="TableControl">
					<td colspan="2" align="center"> <input
						type="button" value="<html:text name="button.delete"/>" class="x-btn"
						 name="delete" id="delete" onclick="javascript:deleteOnclick();">&nbsp;&nbsp;<input
						type="button" value="<html:text name="button.save"/>"
						 name="save" id="save" onclick="javascript:saveOnClick();" class="x-btn">&nbsp;&nbsp;<input type="hidden" id="lastMenuClick" name="lastMenuClick"></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<%@ include file="/WEB-INF/jsp/include/divbottom.jsp"%>
<script type="text/javascript"> 
function saveOnClick(){
		dwr.util.useLoadingMessage();
		var oEditor = FCKeditorAPI.GetInstance("printModel"); 
		var FormSortBean={
				id:_$('formSortId').value
		}; 
		var FormTypeBean={
				formName:_$('formName').value,
				printModel:oEditor.GetHTML(),
				departId:_$('departId').value,
				userScript:_$('userScript').value,
				userCss:_$('userCss').value,
				id:_$('id').value,
				formSortBean:FormSortBean,
				isData:_$('isData').value
		};
		FormSortAction.saveFormType(FormTypeBean,showMessage);
}
function newOnclick(){
	_$('formSortId').value=_$('sortId').value;
	jQuery("#listForm").hide();
	jQuery("#delete").hide();
	jQuery("#detailForm").show(); 
}
function deleteOnclick(){
	var id=_$('id').value;
	FormSortAction.deleteFormType(id,deleteShowMessage);
}

function deleteShowMessage(data){
	if(data=="ok"){
		alert("delete success!");
		//ShowMessageAlert("save success!");
		window.location="index.crm";
	}else{
		alert("delete Failure!");
		//ShowMessageAlert("save Failure!");
	}
}

function showMessage(data){
	if(data=="ok"){
		alert("save success!");
		//ShowMessageAlert("save success!");
		window.location="index.crm";
	}else{
		alert("save Failure!");
		//ShowMessageAlert("save Failure!");
	}
}
	 

function clickMenu(SORT_ID)
{
	dwr.util.useLoadingMessage();
	_$('sortId').value=SORT_ID;
  	FormSortAction.getFormTypesByFormSortId(SORT_ID,updateData(SORT_ID));
}
function delRow(){
	var tableObject=_$('listTable');
	var num=tableObject.rows.length;
	var i=0;
	for(i=num-1;i>0;i--){
		tableObject.deleteRow(i);
	} 
}
function addRow(data,id,i){
	var tableObject=_$('listTable');
	var num=tableObject.rows.length;
	var otr = tableObject.insertRow(num);
	var otd = otr.insertCell(0);
	otd.style.align="center";
	var stringHTML=i; 
	otd.innerHTML=stringHTML;
	var otd1 = otr.insertCell(1); //showCategoryValue
	stringHTML="<a href=\"#\" "; 
	stringHTML=stringHTML+" onclick=\" javascript:view_group('"+data.id;
	stringHTML=stringHTML+"','"+id;
	stringHTML=stringHTML+"');\" >"+data.formName;
	stringHTML=stringHTML+"</a>";
	otd1.innerHTML=stringHTML; 	
}
function updateData(id){
	delRow();
	jQuery("#listForm").show();
	jQuery("#detailForm").hide();
	return function(data){ 
		if (DWRUtil._isArray(data)) {
			var str="";
			for(var i=0;i<data.length;i++){
				addRow(data[i],id,i+1);  
			} 
		}
	};
}
function view_group(id,sortId)
{
	jQuery("#listForm").hide();
	jQuery("#delete").show();
	dwr.util.useLoadingMessage();
	FormSortAction.getFormTypeById(id,updateTableData(sortId));
}
function updateTableData(sortId){
	return function(data){
		var FormSortBean=data.formSortBean;
		dwr.util.setValue("formSortId", FormSortBean.id, { escapeHtml:false });
		dwr.util.setValue("formName", data.formName, { escapeHtml:false });
		dwr.util.setValue("printModel", data.printModel, { escapeHtml:false });
		dwr.util.setValue("departId", data.departId, { escapeHtml:false });
		dwr.util.setValue("userScript", data.userScript, { escapeHtml:false });
		dwr.util.setValue("userCss", data.userCss, { escapeHtml:false });
		dwr.util.setValue("id", data.id, { escapeHtml:false });
		dwr.util.setValue("isData", data.isData, { escapeHtml:false }); 
		var oEditor = FCKeditorAPI.GetInstance("printModel");
		oEditor.SetHTML(data.printModel); 
		jQuery("#detailForm").show(); 
	}
	//objFrame.xEditingArea.value=data.printModel;
	//${'formName'}.value=data.formName;
} 
</script>
</body>
</html>

